package GUI;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import java.awt.Color;
import Componentes.*;
import Juego.Puntaje;
import java.awt.GridLayout;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Grafica extends javax.swing.JFrame {
	
	private JPanel Fondo;
	private JLabel FondoImagen;
	private JPanel PanelPuntaje;
	private JPanel PanelComponentes;
		
	public Grafica(String nombreJuego) {
		super(nombreJuego);
		initGUI();
	}
	
	
	private void initGUI() {
		try {
			this.setLocationByPlatform(true);
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.addWindowListener(new WindowAdapter() {
				public void windowClosing(WindowEvent evt) {
					thisWindowClosing(evt);
				}
			});
			pack();
			this.setSize(500, 600);
			this.setResizable(false);
			getContentPane().setLayout(null);
			getContentPane().setBackground(Color.BLACK);
			{
				PanelComponentes = new JPanel();
				getContentPane().add(PanelComponentes);
				PanelComponentes.setLayout(null);
				PanelComponentes.setBounds(0,0, 495, 580);
				PanelComponentes.setOpaque(false);
				PanelComponentes.setEnabled(true);
				{
					PanelPuntaje = new JPanel();
					GridLayout PanelPuntajeLayout = new GridLayout(1, 1);
					PanelPuntajeLayout.setColumns(1);
					PanelPuntajeLayout.setHgap(5);
					PanelPuntajeLayout.setVgap(5);
					PanelPuntaje.setLayout(PanelPuntajeLayout);
					PanelComponentes.add(PanelPuntaje);
					PanelPuntaje.setBounds(0, 0, 495, 58);
					PanelPuntaje.setOpaque(false);
					PanelPuntaje.setEnabled(true);
				}
			}
			
			{
				Fondo = new JPanel();
				getContentPane().add(Fondo);
				Fondo.setLayout(null);
				Fondo.setBounds(0, 0, 495, 580);
				{
					FondoImagen = new JLabel();
					Fondo.add(FondoImagen);
					Fondo.setBackground(Color.BLACK);
					FondoImagen.setBounds(0, -400, 534, 1000);
					FondoImagen.setOpaque(false);
					ImageIcon fondo = new ImageIcon(Grafica.class.getResource("res/Fondo1.jpg"));
					FondoImagen.setIcon(fondo);
				}

			}

		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	  }
	
	public JLabel obtenerFondo(){
		return FondoImagen;
	}
	
	public void agregarComponente(Componente [] comp) {
		
		for (int i=0; i<comp.length; i++) {
			
		   PanelComponentes.add(comp[i]);
		   }
	  }
	
	public void agregarComponente(Componente c){
		
		PanelComponentes.add(c);
	   }
	
	public void agregarComponente(Puntaje p) {
		
		PanelPuntaje.add(p);
	    }
	
	public void removerComponente(Componente c){
		PanelComponentes.remove(c);
	   }
	
	public void repintarFondo(){
		Fondo.repaint();
	}
	public void repintarComponentes(){
		PanelComponentes.repaint();
	}
	
	//Cerrado de la aplicacion
	private void thisWindowClosing(WindowEvent evt) {
		cerrarJuego();
	}
	
	private void cerrarJuego() {
		this.dispose();
		System.exit(0);
		
	}
	

}
